package com.cmc6.common.util;


import cn.hutool.json.JSONObject;
import com.google.common.base.CaseFormat;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class JsonObjectUtil {

    /**
     * key值：下划线转驼峰
     */
    public static List<JSONObject> changeKey(List<JSONObject> sourceList) {
        List<JSONObject> resList = new ArrayList<>();
        for (JSONObject item : sourceList) {
            JSONObject resJson = new JSONObject();
            for (Map.Entry<String, Object> subItem : item.entrySet()) {
                String key = subItem.getKey();
                Object value = subItem.getValue();
                resJson.set(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, key), value); // 下划线转驼峰
            }
            resList.add(resJson);
        }
        return resList;
    }
}
